# -*- coding: utf-8 -*-
# @Time    : 2019/10/17 9:25
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : dict_method.py
a = {"a1": {"company": "znufe"},
     "b1": {"company": "qf"}}
# clear
# a.clear()
# pass

# copy,返回浅拷贝 只拷贝一层; 深拷贝，将子对象也拷贝
# import copy
# new_dict = copy.deepcopy(a)
# new_dict["a1"]["company"] = "c3"
# pass

# fromkeys  可迭代对象转换为字典
new_list = ["b1", "b2"]
new_dict = dict.fromkeys(new_list, {"company": "znufe"})
print(new_dict)

val = new_dict.get("b", {})
print(val)

print(new_dict.items())

for key, value in new_dict.items():
    for i, j in new_dict[key].items():
        print(i, j)

default_val = new_dict.setdefault("b3", {"company": "imooc"})  # 添加数据，效率较高
print(new_dict)

new_dict.update(b4="i1", b5="i2")  # update 接受可迭代对象更新原有字典
new_dict.update([("b6","i4")])
print(new_dict)